﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Soussous.Business;
using System.Collections.Generic;
using Soussous.DAO.Impl;

namespace Soussous.Template
{
    public partial class home : System.Web.UI.Page
    {
        
            protected void Page_Load(object sender, EventArgs e)
            {
                if (HttpContext.Current.Session["user"] == null) 
                {
                    Response.Redirect("unauthorizedAccess.aspx");
                }
                else{
                    User theUser = (User)HttpContext.Current.Session["user"];
                    message.InnerHtml = theUser.Firstname+" "+theUser.Lastname;
                }
                User theUsers = (User)HttpContext.Current.Session["user"];
                List<Operation> list = OperationDAO.getInstance().searchUser(theUsers.Id);
                
                foreach (Operation ope in list)
                {
                    HtmlTableRow myTableRow = new HtmlTableRow();
                    HtmlTableCell cellule1 = new HtmlTableCell();
                    HtmlTableCell cellule2 = new HtmlTableCell();
                    HtmlTableCell cellule3 = new HtmlTableCell();
                    HtmlTableCell cellule4 = new HtmlTableCell();
                    HtmlTableCell cellule5 = new HtmlTableCell();
                    cellule1.InnerHtml = ope.note.Date.ToString("dd-MM-yy");
                    cellule2.InnerHtml = ope.note.Description;
                    cellule3.InnerHtml = ope.Amount.ToString();
                    cellule4.InnerHtml = "<a href=\"updateNote.aspx?id="+ope.Notes_id+"\" runat=\"server\">Update</a>";
                    myTableRow.Cells.Add(cellule1);
                    myTableRow.Cells.Add(cellule2);
                    myTableRow.Cells.Add(cellule3);
                    myTableRow.Cells.Add(cellule4);
                    
                    table_notes.Rows.Add(myTableRow);

                }

                 var liste = OperationDAO.getInstance().soldeById(theUsers.Id);

                 foreach (var lis in liste) {
                     Response.Write(lis);
                 }
            }
        
    }
}
